package com.jsoft.model;

import com.jsoft.dto.MenuDto;
import com.jsoft.model.core.BaseDao;

import javax.persistence.*;
import java.util.List;

/**
 * Date: 14.09.13
 * Time: 2:08
 */

@Entity
@Table(name = "menus")
public class MenuDao extends BaseDao {
    @Column(name = "name")
    private String name;
    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "sector_id")
    private SectorDao sector;
    @OneToMany(mappedBy = "menu", fetch = FetchType.LAZY)
    private List<MenuGroupDao> menuGroupList;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public SectorDao getSector() {
        return sector;
    }

    public void setSector(SectorDao sector) {
        this.sector = sector;
    }

    public List<MenuGroupDao> getMenuGroupList() {
        return menuGroupList;
    }

    public void setMenuGroupList(List<MenuGroupDao> menuGroupList) {
        this.menuGroupList = menuGroupList;
    }

    public MenuDto wrapMenuDto() {
        MenuDto dto = new MenuDto();
        dto.setId(this.getObjectId());
        dto.setName(this.getName());
        return dto;
    }

    public MenuDao wrapMenuDao(MenuDto dto) {
        MenuDao dao = new MenuDao();
        dao.setName(dto.getName());
        return dao;
    }
}
